﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;
using Helper;
namespace SchoolManagementSystem.Details
{
    public partial class Student_ResultDetailUC : DetailUC
    {
        public Student_ResultDetailUC()
        {
            InitializeComponent();
            this.Code = "Student_ResultDetail";
            this.ObjectName = "kết qua học tập";
            this.Type = new Student_Result();
            commandBarUC1.cmdnew.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
        }


        protected override long DetailDisplay()
        {
            commandBarUC1.cmdnew.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            commandBarUC1.cmdsave.Enabled = true;
            Student_Result data = new Student_Result();
            if (ID > 0)
            {
                data =RegisterService.RegisterServices.StudentResultDetailService.GetByID(ID) as Student_Result;
            }
            txtnumber.Text = data.Value.ToString();
            if (data.LockExt)
            {
                txtnumber.Enabled = false;
            }
            else
            {
                txtnumber.Enabled = true;
            }
            return ID;

        }

        protected override long Save()
        {
            var datas = MasterUC.GridViewMasterUC;

            for(int i=0;i<datas.RowCount;i++)
            {
                try
                {
                    Student_Result data = new Student_Result();
                    var id = (long)datas.GetRowCellValue(i, "ID");
                   // if (ID > 0)
                    {
                        data = RegisterService.RegisterServices.StudentResultDetailService.GetByID(id) as Student_Result;
                    }
                    data.Value = ConvertObject.ToInt(datas.GetRowCellValue(i, "Value").ToString());
                    ID = RegisterService.RegisterServices.StudentResultService.Save(data);
                }
                catch
                {
                    
                }
            }

            commandBarUC1.cmdsave.Enabled = false;
            return ID;
        }


        public override bool Delete(long SelectedID)
        {
            return RegisterService.RegisterServices.StudentResultService.Delete(RegisterService.RegisterServices.StudentResultService.GetByID(SelectedID));

        }

        private void Student_ResultDetailUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(groupControl1.Controls);
        }

    }
}
